home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Online / hsc / docs-source / features / if.hsc < prev    next >
Encoding:
Text File  |  1997-10-12  |  3.6 KB  |  123 lines

  1. <WEBPAGE chapter="hsc - Features - "
  2.     title="Conditionals"
  3.     PREV=":macro/attrib.html"
  4.     NEXT="prefs.html">
  5.  
  6. <H2><A NAME="general">General Syntax</A></H2>
  7.  
  8. Conditionals looks like that:
  9.  
  10. <PRE>
  11. <CODE><$if COND=</CODE><I><A HREF="expressions.html">expression</A></I><CODE>></CODE>
  12.  
  13.   <I>code to be processed if condition matches</I>
  14.  
  15. <CODE><$elseif COND=</CODE><I><A HREF="expressions.html">expression</A></I><CODE>></CODE>
  16.  
  17.   <I>(optional) code to be processed if alternative condition matches;
  18.      this can occur multiple times</I>
  19.  
  20. <CODE><$else></CODE>
  21.  
  22.   <I>(optional) code to be processed if none of the previous conditions matched</I>
  23.  
  24. <CODE></$if></CODE>
  25. </PRE>
  26.  
  27. <P>Both <TG>$if</TG> and <TG>$elseif</TG> require a boolean attribute 
  28. <CODE>COND</CODE>; <CODE>false</CODE> is represented by an empty string,
  29. <CODE>true</CODE> by any non-empty string. Normally, you will like to
  30. set <CODE>COND</CODE> using
  31. <A HREF="expressions.html">expressions</A>.</P>
  32.  
  33. <H2><A NAME="simple">Some Simple Examples</A></H2>
  34.  
  35. Now let's see how this works in practice:
  36.  
  37. <$SOURCE PRE>
  38.     <$if COND=(NAME="sepp")>
  39.        You must be sepp!
  40.     </$if>
  41. </$SOURCE>
  42.  
  43. <P>This one inserts the text "<CODE>You must be sepp!</CODE>", if the attribute
  44. <CODE>NAME</CODE> has the value "<CODE>sepp</CODE>". Note that the 
  45. "<CODE>=</CODE>"-operator performs a case-insensitive string-comparison,
  46. so setting <CODE>NAME="SEPP"</CODE> would lead to the same result.</P>
  47.  
  48. Now let's extend this:
  49.  
  50. <$SOURCE PRE>
  51.     <$if COND=(NAME="sepp")>
  52.        You must be sepp!
  53.     <$else>
  54.        I don't know you.
  55.     </$if>
  56. </$SOURCE>
  57.  
  58. <P>Setting <CODE>NAME="sepp"</CODE> will create the same text as above. Any
  59. other value for <CODE>NAME</CODE> will insert 
  60. "<CODE>I don't know you.</CODE>".</P>
  61.  
  62. <H2><A NAME="nesting">Nesting Conditionals</A></H2>
  63.  
  64. <P>Nesting them is also possible, of course:</P>
  65.  
  66. <$SOURCE PRE>
  67.     <$if COND=(NAME="sepp")>
  68.        You must be sepp!
  69.        <$if COND=(HOME="austria")>
  70.            Hollareiduliö! An Austrian!
  71.        <$else>
  72.            <(HOME)>? Never been there.
  73.        </$if>
  74.     <$else>
  75.        A strange guy from a strange place.
  76.     </$if>
  77. </$SOURCE>
  78.  
  79.  
  80. <H2><A NAME="macros">Conditionals And Macros</A></H2>
  81.  
  82. <P>You can not compare <hsc>'s <TG>$if</TG> to primitive and clumsy 
  83. <CODE>#if</CODE> of the C-preprocessor. The main difference is that 
  84. you can use <TG>$if</TG> inside macros and that expressions are 
  85. recalculated for every new call of the macro.</P>
  86.  
  87. <$SOURCE PRE>
  88.     <$macro TRY-A HREF:uri/r TITLE:string/r>
  89.     <$if COND=(Exists(HREF))>
  90.         <A HREF=(HREF)><(TITLE)></A> <* insert link to HREF *>
  91.     <$else>
  92.         <(TITLE)>                    <* insert plain title *>
  93.     </$if>
  94.     </$macro>
  95. </$SOURCE>
  96.  
  97. <P>This one inserts a link to an URI specified with <CODE>HREF</CODE>,
  98. using <CODE>TITLE</CODE> as link text; but only, if the destination
  99. (local) URI can be accessed. If the required document is not
  100. available, only the plain text without a link will be inserted.</P>
  101.  
  102. <P>The "<CODE>/r</CODE>" behind the declaration of the
  103. macro-attributes is short for "<CODE>/required</CODE>" and means that
  104. the macro needs both of these attributes to be set during the
  105. macro-call.</P>
  106.  
  107. <P>For example, you can utilize this macro using</P>
  108.  
  109. <$SOURCE PRE>
  110.     You should read the document about recent
  111.     <TRY-A HREF="../bugfixes.html" TITLE="bufixes">
  112.     if there are any.
  113. </$SOURCE>
  114.  
  115. <P>This leads to the text</P>
  116. <PRE>
  117.     You should read the document about recent bugfixes if there are any.
  118. </PRE>
  119. <P>with a anchor around the term "<CODE>bugfixes</CODE>" if the document
  120. "<FILE>../bugfixes.html</FILE>" exists.</P>
  121.  
  122. </WEBPAGE>
  123.